/* new_map_window.c */

#include <stdlib.h>

#include "SDL.h"
#include "SDL_gfxPrimitives.h"

#include "new_map_window.h"
#include "dialog.h"
#include "graphics.h"
#include "selection.h"
#include "path.h"
#include "maps.h"

static char new_map_name[256] = "";

static void proc_new_map_cancel(DLG_WIDGET *widget, int note)
{
  widget->dlg->widget[0].d1 = 0;
  dlg_end(widget->dlg);
}

static void proc_new_map_ok(DLG_WIDGET *widget, int note)
{
  widget->dlg->widget[0].d1 = 1;
  dlg_end(widget->dlg);
}

DIALOG new_map_dialog = {
  {
    DLG_WIDGET_SCREEN(0x000044ff, NULL),
    
    DLG_WIDGET_LABEL(300, 140, "Map name:"),
    DLG_WIDGET_EDIT (300, 150, 200, new_map_name, sizeof(new_map_name), NULL),

    DLG_WIDGET_BUTTON(300, 200, 60, "OK", proc_new_map_ok),
    DLG_WIDGET_BUTTON(370, 200, 60, "Cancel", proc_new_map_cancel),
  },
};

int new_map_window(SDL_Surface *screen, char *ret_map_name, int max_size)
{
  int n;
  for (n = 0; map_name_items[n] != NULL; n++)
    ;
  snprintf(new_map_name, sizeof(new_map_name), "map%02d", n+1);
  
  dlg_run(&new_map_dialog, screen, 0);
  if (new_map_dialog.widget[0].d1) {
    strncpy(ret_map_name, new_map_name, max_size);
    ret_map_name[max_size-1] = '\0';
    return 1;
  }
  return 0;
}
